package com.wisedu.jwjob;

import org.apache.log4j.Logger;
import org.nutz.boot.NbApp;
import org.nutz.dao.Cnd;
import org.nutz.integration.quartz.QuartzJob;
import org.nutz.integration.quartz.QuartzManager;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.*;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.*;
import com.wisedu.jwjob.bean.User;
import org.nutz.dao.Dao;
import org.quartz.Scheduler;

import java.util.List;

@IocBean(create="init", depose="depose")
public class MainLauncher {
    private static final Log log = Logs.get();
    @Inject
    protected PropertiesProxy conf;
    @Inject("refer:$ioc")
    private Ioc ioc;
    @At("/")
    @Ok("->:/index.html")
    public void index() {}
    
    public void init() {
        // NB自身初始化完成后会调用这个方法
    }
    public void depose() {
        log.info("depose Sys Task");
        QuartzManager quartzManager = ioc.get(QuartzManager.class);
        quartzManager.clear();
        // 解决quartz有时候无法停止的问题
        try {
            ioc.get(Scheduler.class).shutdown(true);
        } catch (Exception e) {

        }
    }

    public static void main(String[] args) throws Exception {
        new NbApp().setArgs(args).setPrintProcDoc(true).run();
    }
    /**
     * 初始化 定时任务
     * @param ioc
     */
    private void initSysTask(Ioc ioc) {
        QuartzManager quartzManager = ioc.get(QuartzManager.class);
        quartzManager.clear();
            try {
                QuartzJob qj = new QuartzJob();
                qj.setJobName("BdaoJob");
                qj.setJobGroup("BdaoJob");
                qj.setClassName("com.wisedu.jwjob.job.BdaoJob");
                qj.setCron("0 0/1 * * * ?");
                qj.setComment("每天查询当天人脸识别情况");
                qj.setDataMap("");
                quartzManager.add(qj);
            } catch (Exception e) {
                log.error(e.getMessage());
            }
    }
}
